//用户登录日志接口
var express = require('express');
var router = express.Router();
const mysql = require('mysql2/promise');

// 导入处理.env文件的模块dotenv
require('dotenv').config();

const pool=mysql.createPool({
  host:process.env.DB_HOST,
  user:process.env.DB_USER,
  password:process.env.DB_PASSWORD,
  database:process.env.DB_DATABASE,
  connectionLimit: 10,
  waitForConnections: true,
  queueLimit: 0
})

/* GET user_login_logs listing. */
router.get('/', async function(req, res, next) {
try {
  // 创建一个数据库连接
  const connection = await pool.getConnection();

  // execute 将在内部调用 prepare 和 query
  const [results, fields] = await connection.execute(
    'SELECT * FROM `user_login_logs`'
  );

  console.log(results); // 结果集
  console.log(fields); // 额外的元数据（如果有的话）
  res.send(results);
} catch (err) {
  console.log(err);
}
});

module.exports = router;
